package com.example.boot.dladvertising.service.impl;

import com.example.boot.dladvertising.service.DlAdvertisingService;
import com.example.boot.dladvertising.vo.AllIndexData;
import com.example.boot.dladvertising.vo.WeChatIndex;
import com.example.boot.dlbigtype.dao.DlBigTypeMapper;
import com.example.boot.dlgoods.dao.DlGoodsMapper;
import com.example.boot.dlgoodsmodel.dao.DlGoodsModelMapper;
import com.example.boot.dlgoodsmodel.model.DlGoodsModel;
import com.example.boot.dlgoodsmodel.vo.ModelType;
import com.example.boot.dlgoodspic.dao.DlGoodsPicMapper;
import com.example.boot.dlorder.dao.DlOrderMapper;
import com.example.boot.dlorderevaluate.dao.DlOrderEvaluateMapper;
import com.example.boot.tstype.dao.TSTypeMapper;
import com.example.boot.tstype.model.TSType;
import com.example.boot.util.NumberDictionary;
import com.example.boot.util.PicURLEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DlAdvertisingImpl implements DlAdvertisingService {
	// @Autowired
	// private DlAdvertisingMapper dlAdvertisingMapper;
	@Autowired
	private DlGoodsMapper dlGoodsMapper;
	@Autowired
	private DlBigTypeMapper dlBigTypeMapper;
	@Autowired
	private DlOrderEvaluateMapper dlOrderEvaluateMapper;
	@Autowired
	private PicURLEntity picURLEntity;
	@Autowired
	private DlGoodsPicMapper dlGoodsPicMapper;
	@Autowired
	private DlOrderMapper dlOrderMapper;
	@Autowired
	private DlGoodsModelMapper dlGoodsModelMapper;
	@Autowired
	private TSTypeMapper tsTypeMapper;
	@Autowired
	private NumberDictionary numberDictionary;

	/**
	 * 查询首页
	 * 
	 * @throws Exception
	 */
	@Autowired
	@Transactional
	@Override
	public Object wechatIndex() throws Exception {
		AllIndexData data = new AllIndexData();
		List<WeChatIndex> findByGoodsAdvertising = dlGoodsMapper.findByGoodsAdvertising();
		List<WeChatIndex> findByTypeAdvertising = dlBigTypeMapper.findByTypeAdvertising();
		List<DlGoodsModel> findAllModel = dlGoodsModelMapper.findAllModel();
		List<ModelType> findType = dlGoodsModelMapper.findType();
		for (ModelType type : findType) {
			TSType byIdAndTypeFind = tsTypeMapper.byIdAndTypeFind(numberDictionary.getModelType(), type.getTypeSort());
			type.setModelName(byIdAndTypeFind.getTypename());

		}
		for (WeChatIndex index : findByGoodsAdvertising) {
			index.setPictureStr(picURLEntity.getUrlPrefix() +index.getPictureStr());
		}
		for (WeChatIndex index : findByTypeAdvertising) {
			index.setPictureStr(picURLEntity.getUrlPrefix() + index.getPictureStr());
		}

		for (DlGoodsModel model : findAllModel) {
			String goodsId = model.getGoodsId();
			TSType byIdAndTypeFind = tsTypeMapper.byIdAndTypeFind(numberDictionary.getModelType(),
					model.getModelType());
			model.setModelName(byIdAndTypeFind.getTypename());
			model.setPictureStr(picURLEntity.getUrlPrefix() + model.getPictureStr());
			model.setScore(dlOrderEvaluateMapper.findByGoodsEvaluate(goodsId));
			model.setDescribeScore(dlOrderEvaluateMapper.findByDescribeScoreScoreGoodsEvaluate(goodsId));
			model.setQualityScore(dlOrderEvaluateMapper.findByQualityScoreGoodsEvaluate(goodsId));
			model.setSalesVolume(dlOrderMapper.byGoodsIdFindSum(goodsId));
		}
		findByGoodsAdvertising.addAll(findByTypeAdvertising);// 广告
		data.setTypelist(findType);
		data.setAdvertisingList(findByGoodsAdvertising);
		data.setModelList(findAllModel);
		return data;
	}

}
